﻿using Springwater.DataAccessLayer.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Springwater.Business.ViewModels
{
    public class ViewAllModel
    {
        public decimal Latitude { get; set; }
        public decimal Longitude { get; set; } 
        public List<BorvizSummaryModel> BorvizSummaryModelList { get; set; }

        public ViewAllModel(UnitOfWork unitOfWork)
        {
            BorvizSummaryModelList = new List<BorvizSummaryModel>();
            unitOfWork.BorvizRepository.Get().Where(b => b.FoldfelsziniHelyzet != null).ToList().ForEach(b => BorvizSummaryModelList.Add(new BorvizSummaryModel(b, true)));
            BorvizSummaryModelList = BorvizSummaryModelList.Where(b => b.HasGps).ToList();

            this.Latitude = (BorvizSummaryModelList.Min(b => b.Latitude) + BorvizSummaryModelList.Max(b => b.Latitude)) / 2;
            this.Longitude = (BorvizSummaryModelList.Min(b => b.Longitude) + BorvizSummaryModelList.Max(b => b.Longitude)) / 2; 
        }
    }
}
